<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE BangPatterns #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-3"></span><span class="hs-pragma">{-# LANGUAGE DoAndIfThenElse #-}</span><span>
</span><span id="line-4"></span><span class="hs-pragma">{-# LANGUAGE ForeignFunctionInterface #-}</span><span>
</span><span id="line-5"></span><span class="hs-pragma">{-# LANGUAGE EmptyDataDecls #-}</span><span>
</span><span id="line-6"></span><span class="hs-pragma">{-# LANGUAGE RecordWildCards #-}</span><span>
</span><span id="line-7"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude #-}</span><span>
</span><span id="line-8"></span><span>
</span><span id="line-9"></span><span class="hs-comment">-------------------------------------------------------------------------------</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Module      :  GHC.Event.Windows.ManagedThreadPool</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Copyright   :  (c) Tamar Christina 2019</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-14"></span><span class="hs-comment">--</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- Stability   :  experimental</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- Portability :  non-portable</span><span>
</span><span id="line-18"></span><span class="hs-comment">--</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- WinIO Windows Managed Thread pool API.  This thread pool scales dynamically</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- based on demand.</span><span>
</span><span id="line-21"></span><span class="hs-comment">--</span><span>
</span><span id="line-22"></span><span class="hs-comment">-------------------------------------------------------------------------------</span><span>
</span><span id="line-23"></span><span>
</span><span id="line-24"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Event.Windows.ManagedThreadPool</span><span>
</span><span id="line-25"></span><span>  </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#ThreadPool"><span class="hs-identifier">ThreadPool</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-26"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#startThreadPool"><span class="hs-identifier">startThreadPool</span></a></span><span>
</span><span id="line-27"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#notifyRunning"><span class="hs-identifier">notifyRunning</span></a></span><span>
</span><span id="line-28"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#notifyWaiting"><span class="hs-identifier">notifyWaiting</span></a></span><span>
</span><span id="line-29"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#monitorThreadPool"><span class="hs-identifier">monitorThreadPool</span></a></span><span>
</span><span id="line-30"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-31"></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Control.Concurrent.MVar.html"><span class="hs-identifier">Control.Concurrent.MVar</span></a></span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Maybe.html"><span class="hs-identifier">Data.Maybe</span></a></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.html"><span class="hs-identifier">Foreign</span></a></span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Num.html"><span class="hs-identifier">GHC.Num</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">-</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Num.html#%2B"><span class="hs-operator">(+)</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier">fromIntegral</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.Event.Array.html"><span class="hs-identifier">GHC.Event.Array</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">A</span></span><span>
</span><span id="line-39"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html"><span class="hs-identifier">GHC.IO.Handle.Internals</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier">debugIO</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html"><span class="hs-identifier">GHC.Conc.Sync</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier">ThreadId</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.RTS.Flags.html"><span class="hs-identifier">GHC.RTS.Flags</span></a></span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span class="hs-comment">------------------------------------------------------------------------</span><span>
</span><span id="line-44"></span><span class="hs-comment">-- Thread spool manager</span><span>
</span><span id="line-45"></span><span>
</span><span id="line-46"></span><span class="hs-keyword">type</span><span> </span><span id="WorkerJob"><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#WorkerJob"><span class="hs-identifier hs-var">WorkerJob</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-47"></span><span>
</span><span id="line-48"></span><span class="hs-comment">-- | Thread pool manager state</span><span>
</span><span id="line-49"></span><span class="hs-keyword">data</span><span> </span><span id="ThreadPool"><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#ThreadPool"><span class="hs-identifier hs-var">ThreadPool</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="ThreadPool"><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#ThreadPool"><span class="hs-identifier hs-var">ThreadPool</span></a></span></span><span>
</span><span id="line-50"></span><span>  </span><span class="hs-special">{</span><span> </span><span id="thrMainThread"><span class="annot"><span class="annottext">ThreadPool -&gt; Maybe ThreadId
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#thrMainThread"><span class="hs-identifier hs-var hs-var">thrMainThread</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span>
</span><span id="line-51"></span><span>  </span><span class="hs-special">,</span><span> </span><span id="thrMaxThreads"><span class="annot"><span class="annottext">ThreadPool -&gt; Int
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#thrMaxThreads"><span class="hs-identifier hs-var hs-var">thrMaxThreads</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-52"></span><span>  </span><span class="hs-special">,</span><span> </span><span id="thrMinThreads"><span class="annot"><span class="annottext">ThreadPool -&gt; Int
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#thrMinThreads"><span class="hs-identifier hs-var hs-var">thrMinThreads</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-53"></span><span>  </span><span class="hs-special">,</span><span> </span><span id="thrCurThreads"><span class="annot"><span class="annottext">ThreadPool -&gt; Int
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#thrCurThreads"><span class="hs-identifier hs-var hs-var">thrCurThreads</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-54"></span><span>  </span><span class="hs-special">,</span><span> </span><span id="thrCallBack"><span class="annot"><span class="annottext">ThreadPool -&gt; WorkerJob
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#thrCallBack"><span class="hs-identifier hs-var hs-var">thrCallBack</span></a></span></span><span>      </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#WorkerJob"><span class="hs-identifier hs-type">WorkerJob</span></a></span><span>
</span><span id="line-55"></span><span>  </span><span class="hs-special">,</span><span> </span><span id="thrActiveThreads"><span class="annot"><span class="annottext">ThreadPool -&gt; MVar Int
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#thrActiveThreads"><span class="hs-identifier hs-var hs-var">thrActiveThreads</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-56"></span><span>  </span><span class="hs-special">,</span><span> </span><span id="thrMonitor"><span class="annot"><span class="annottext">ThreadPool -&gt; MVar ()
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#thrMonitor"><span class="hs-identifier hs-var hs-var">thrMonitor</span></a></span></span><span>       </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-57"></span><span>  </span><span class="hs-special">,</span><span> </span><span id="thrThreadIds"><span class="annot"><span class="annottext">ThreadPool -&gt; Array ThreadId
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#thrThreadIds"><span class="hs-identifier hs-var hs-var">thrThreadIds</span></a></span></span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="hs-pragma">{-#UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Event.Array.html#Array"><span class="hs-identifier hs-type">A.Array</span></a></span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html#ThreadId"><span class="hs-identifier hs-type">ThreadId</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-58"></span><span>  </span><span class="hs-special">}</span><span>
</span><span id="line-59"></span><span>
</span><span id="line-60"></span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#startThreadPool"><span class="hs-identifier hs-type">startThreadPool</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#WorkerJob"><span class="hs-identifier hs-type">WorkerJob</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#ThreadPool"><span class="hs-identifier hs-type">ThreadPool</span></a></span><span>
</span><span id="line-61"></span><span id="startThreadPool"><span class="annot"><span class="annottext">startThreadPool :: WorkerJob -&gt; IO ThreadPool
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#startThreadPool"><span class="hs-identifier hs-var hs-var">startThreadPool</span></a></span></span><span> </span><span id="local-6989586621679550002"><span class="annot"><span class="annottext">WorkerJob
</span><a href="#local-6989586621679550002"><span class="hs-identifier hs-var">job</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-62"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; WorkerJob
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Starting I/O manager threadpool...&quot;</span></span><span>
</span><span id="line-63"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679550000"><span class="annot"><span class="annottext">thrMinThreads :: Int
</span><a href="#local-6989586621679550000"><span class="hs-identifier hs-var hs-var">thrMinThreads</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span>
</span><span id="line-64"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679549998"><span class="annot"><span class="annottext">thrCurThreads :: Int
</span><a href="#local-6989586621679549998"><span class="hs-identifier hs-var hs-var">thrCurThreads</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-65"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679549997"><span class="annot"><span class="annottext">thrCallBack :: WorkerJob
</span><a href="#local-6989586621679549997"><span class="hs-identifier hs-var hs-var">thrCallBack</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">WorkerJob
</span><a href="#local-6989586621679550002"><span class="hs-identifier hs-var">job</span></a></span><span>
</span><span id="line-66"></span><span>  </span><span id="local-6989586621679549996"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679549996"><span class="hs-identifier hs-var">thrMaxThreads</span></a></span></span><span>     </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word32 -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">(Word32 -&gt; Int) -&gt; (MiscFlags -&gt; Word32) -&gt; MiscFlags -&gt; Int
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">MiscFlags -&gt; Word32
</span><a href="GHC.RTS.Flags.html#numIoWorkerThreads"><span class="hs-identifier hs-var hs-var">numIoWorkerThreads</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(MiscFlags -&gt; Int) -&gt; IO MiscFlags -&gt; IO Int
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-operator hs-var">`fmap`</span></a></span><span> </span><span class="annot"><span class="annottext">IO MiscFlags
</span><a href="GHC.RTS.Flags.html#getMiscFlags"><span class="hs-identifier hs-var">getMiscFlags</span></a></span><span>
</span><span id="line-67"></span><span>  </span><span id="local-6989586621679549992"><span class="annot"><span class="annottext">MVar Int
</span><a href="#local-6989586621679549992"><span class="hs-identifier hs-var">thrActiveThreads</span></a></span></span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO (MVar Int)
forall a. a -&gt; IO (MVar a)
</span><a href="GHC.MVar.html#newMVar"><span class="hs-identifier hs-var">newMVar</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-68"></span><span>  </span><span id="local-6989586621679549990"><span class="annot"><span class="annottext">MVar ()
</span><a href="#local-6989586621679549990"><span class="hs-identifier hs-var">thrMonitor</span></a></span></span><span>        </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO (MVar ())
forall a. IO (MVar a)
</span><a href="GHC.MVar.html#newEmptyMVar"><span class="hs-identifier hs-var">newEmptyMVar</span></a></span><span>
</span><span id="line-69"></span><span>  </span><span id="local-6989586621679549988"><span class="annot"><span class="annottext">Array ThreadId
</span><a href="#local-6989586621679549988"><span class="hs-identifier hs-var">thrThreadIds</span></a></span></span><span>      </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO (Array ThreadId)
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-comment">-- A.new thrMaxThreads</span><span>
</span><span id="line-70"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679549986"><span class="annot"><span class="annottext">thrMainThread :: Maybe a
</span><a href="#local-6989586621679549986"><span class="hs-identifier hs-var hs-var">thrMainThread</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-71"></span><span>
</span><span id="line-72"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679549985"><span class="annot"><span class="annottext">pool :: ThreadPool
</span><a href="#local-6989586621679549985"><span class="hs-identifier hs-var hs-var">pool</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ThreadPool :: Maybe ThreadId
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; WorkerJob
-&gt; MVar Int
-&gt; MVar ()
-&gt; Array ThreadId
-&gt; ThreadPool
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#ThreadPool"><span class="hs-identifier hs-type">ThreadPool</span></a></span><span class="hs-special">{</span><span class="annot"><span class="annottext">Int
Maybe ThreadId
WorkerJob
MVar Int
MVar ()
Array ThreadId
forall a. Maybe a
thrMainThread :: forall a. Maybe a
thrThreadIds :: Array ThreadId
thrMonitor :: MVar ()
thrActiveThreads :: MVar Int
thrMaxThreads :: Int
thrCallBack :: WorkerJob
thrCurThreads :: Int
thrMinThreads :: Int
thrThreadIds :: Array ThreadId
thrMonitor :: MVar ()
thrActiveThreads :: MVar Int
thrCallBack :: WorkerJob
thrCurThreads :: Int
thrMinThreads :: Int
thrMaxThreads :: Int
thrMainThread :: Maybe ThreadId
</span><a href="#local-6989586621679549986"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span><span class="hs-special">}</span><span>
</span><span id="line-73"></span><span>  </span><span class="annot"><span class="annottext">ThreadPool -&gt; IO ThreadPool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadPool
</span><a href="#local-6989586621679549985"><span class="hs-identifier hs-var">pool</span></a></span><span>
</span><span id="line-74"></span><span>
</span><span id="line-75"></span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#monitorThreadPool"><span class="hs-identifier hs-type">monitorThreadPool</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-76"></span><span id="monitorThreadPool"><span class="annot"><span class="annottext">monitorThreadPool :: MVar () -&gt; WorkerJob
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#monitorThreadPool"><span class="hs-identifier hs-var hs-var">monitorThreadPool</span></a></span></span><span> </span><span id="local-6989586621679549984"><span class="annot"><span class="annottext">MVar ()
</span><a href="#local-6989586621679549984"><span class="hs-identifier hs-var">monitor</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-77"></span><span>  </span><span id="local-6989586621679549983"><span class="annot"><span class="annottext">()
</span><a href="#local-6989586621679549983"><span class="hs-identifier hs-var">_active</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">MVar () -&gt; WorkerJob
forall a. MVar a -&gt; IO a
</span><a href="GHC.MVar.html#takeMVar"><span class="hs-identifier hs-var">takeMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar ()
</span><a href="#local-6989586621679549984"><span class="hs-identifier hs-var">monitor</span></a></span><span>
</span><span id="line-78"></span><span>
</span><span id="line-79"></span><span>  </span><span class="annot"><span class="annottext">() -&gt; WorkerJob
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-80"></span><span>
</span><span id="line-81"></span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#notifyRunning"><span class="hs-identifier hs-type">notifyRunning</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#ThreadPool"><span class="hs-identifier hs-type">ThreadPool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-82"></span><span id="notifyRunning"><span class="annot"><span class="annottext">notifyRunning :: Maybe ThreadPool -&gt; WorkerJob
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#notifyRunning"><span class="hs-identifier hs-var hs-var">notifyRunning</span></a></span></span><span> </span><span class="annot"><span class="annottext">Maybe ThreadPool
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; WorkerJob
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-83"></span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#notifyRunning"><span class="hs-identifier hs-var">notifyRunning</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679549981"><span class="annot"><span class="annottext">ThreadPool
</span><a href="#local-6989586621679549981"><span class="hs-identifier hs-var">pool</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-84"></span><span>  </span><span class="annot"><span class="annottext">MVar Int -&gt; (Int -&gt; IO Int) -&gt; WorkerJob
forall a. MVar a -&gt; (a -&gt; IO a) -&gt; WorkerJob
</span><a href="Control.Concurrent.MVar.html#modifyMVar_"><span class="hs-identifier hs-var">modifyMVar_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ThreadPool -&gt; MVar Int
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#thrActiveThreads"><span class="hs-identifier hs-var hs-var">thrActiveThreads</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadPool
</span><a href="#local-6989586621679549981"><span class="hs-identifier hs-var">pool</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679549979"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679549979"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(Int -&gt; IO Int) -&gt; Int -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679549979"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-85"></span><span>  </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">MVar () -&gt; () -&gt; IO Bool
forall a. MVar a -&gt; a -&gt; IO Bool
</span><a href="GHC.MVar.html#tryPutMVar"><span class="hs-identifier hs-var">tryPutMVar</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ThreadPool -&gt; MVar ()
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#thrMonitor"><span class="hs-identifier hs-var hs-var">thrMonitor</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadPool
</span><a href="#local-6989586621679549981"><span class="hs-identifier hs-var">pool</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-86"></span><span>  </span><span class="annot"><span class="annottext">() -&gt; WorkerJob
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-87"></span><span>
</span><span id="line-88"></span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#notifyWaiting"><span class="hs-identifier hs-type">notifyWaiting</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#ThreadPool"><span class="hs-identifier hs-type">ThreadPool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-89"></span><span id="notifyWaiting"><span class="annot"><span class="annottext">notifyWaiting :: Maybe ThreadPool -&gt; WorkerJob
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#notifyWaiting"><span class="hs-identifier hs-var hs-var">notifyWaiting</span></a></span></span><span> </span><span class="annot"><span class="annottext">Maybe ThreadPool
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; WorkerJob
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-90"></span><span class="annot"><a href="GHC.Event.Windows.ManagedThreadPool.html#notifyWaiting"><span class="hs-identifier hs-var">notifyWaiting</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679549977"><span class="annot"><span class="annottext">ThreadPool
</span><a href="#local-6989586621679549977"><span class="hs-identifier hs-var">pool</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-91"></span><span>  </span><span class="annot"><span class="annottext">MVar Int -&gt; (Int -&gt; IO Int) -&gt; WorkerJob
forall a. MVar a -&gt; (a -&gt; IO a) -&gt; WorkerJob
</span><a href="Control.Concurrent.MVar.html#modifyMVar_"><span class="hs-identifier hs-var">modifyMVar_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ThreadPool -&gt; MVar Int
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#thrActiveThreads"><span class="hs-identifier hs-var hs-var">thrActiveThreads</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadPool
</span><a href="#local-6989586621679549977"><span class="hs-identifier hs-var">pool</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679549976"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679549976"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(Int -&gt; IO Int) -&gt; Int -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679549976"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-92"></span><span>  </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">MVar () -&gt; () -&gt; IO Bool
forall a. MVar a -&gt; a -&gt; IO Bool
</span><a href="GHC.MVar.html#tryPutMVar"><span class="hs-identifier hs-var">tryPutMVar</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ThreadPool -&gt; MVar ()
</span><a href="GHC.Event.Windows.ManagedThreadPool.html#thrMonitor"><span class="hs-identifier hs-var hs-var">thrMonitor</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadPool
</span><a href="#local-6989586621679549977"><span class="hs-identifier hs-var">pool</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-93"></span><span>  </span><span class="annot"><span class="annottext">() -&gt; WorkerJob
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-94"></span></pre></body></html>